#include "PlatformProperty.h"

MAPPING_VALUE(SeatLengthMode, sdb::SwtHozlSts1, sdb::SwtHozlSts1::Idle)
MAPPING_ITEM(SeatLengthMode::SEAT_LENGTH_OFF, sdb::SwtHozlSts1::Idle)
MAPPING_ITEM(SeatLengthMode::SEAT_LENGTH_FORWARD, sdb::SwtHozlSts1::Fwd)
MAPPING_ITEM(SeatLengthMode::SEAT_LENGTH_BACKWARD, sdb::SwtHozlSts1::Backw)
MAPPING_END
MAPPING_VALUE(sdb::SwtHozlSts1, SeatLengthMode, SeatLengthMode::SEAT_LENGTH_OFF)
MAPPING_ITEM(sdb::SwtHozlSts1::Idle, SeatLengthMode::SEAT_LENGTH_OFF)
MAPPING_ITEM(sdb::SwtHozlSts1::Fwd, SeatLengthMode::SEAT_LENGTH_FORWARD)
MAPPING_ITEM(sdb::SwtHozlSts1::Backw, SeatLengthMode::SEAT_LENGTH_BACKWARD)
MAPPING_END

sdb::Boolean m_LastDrvrSeatExtAdjAllowdMove_SeatExt = sdb::Boolean::FALSE;
sdb::SwtHozlSts1 last_Drvalue = sdb::SwtHozlSts1::Idle;
sdb::SwtHozlSts1 last_Passvalue = sdb::SwtHozlSts1::Idle;
std::map<int32_t, int32_t> m_SeatAdjustmentVFCMove;

// HY11 [SW_FC_004_043]第一排座椅滑移1stRowSeatLengthAdjustment
void SeatAdjustmentChangeVFCMove_IdleToOther(SignalTX iSignal, int32_t iValue) {
    int32_t ikey = static_cast<int32_t>(iSignal);
    std::map<int32_t, int32_t>::iterator it = m_SeatAdjustmentVFCMove.find(ikey);
    if (!(it != m_SeatAdjustmentVFCMove.end())) {
        m_SeatAdjustmentVFCMove[ikey] = 0;
    }
    VHALOG.d("SeatAdjustmentChangeVFCMove_IdleToOther-iValue=%d,last=%d,Signal=%d,key=%d", iValue,
             m_SeatAdjustmentVFCMove[ikey], iSignal, ikey);
    // VFC 开启
    if (0 == m_SeatAdjustmentVFCMove[ikey] && 0 != iValue &&
        !SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModAbdnd)) {
        SIGNAL.setCB_VFC_SeatComfortFunctions(sdb::OnOff1::On);
    }
    m_SeatAdjustmentVFCMove[ikey] = iValue;
}

SYSTEM_READ_WRITE_PROPERTY(SEAT_FORE_AFT_MOVE, SeatLengthMode) {
    builder.area(VehicleAreaSeat::ROW_1_LEFT)
        .initValue([]() { return SeatLengthMode::SEAT_LENGTH_OFF; })
        .withStatusBySignals(
            []([[maybe_unused]] const PropertyStatus& last) {
                sdb::Boolean drvrSeatExtAdjAllowd = SIGNAL.getDrvrSeatExtAdjAllowd();
                sdb::Timeout drvrSeatExtAdjAllowdTimeout = SIGNAL.getDrvrSeatExtAdjAllowdTimeout();
                sdb::GearLvrIndcn2 gearLvrIndcn = SIGNAL.getGearLvrIndcn();
                auto drvrSeatBtnPsd = SIGNAL.getDrvrSeatBtnPsd();
                VHALOG.d(
                    "SEAT_FORE_AFT_MOVE drvr carmod[%d], "
                    "usgmod[%d], cc472[%d], cc1173[%d], DrvrSeatExtAdjAllowd[%d], "
                    "DrvrSeatExtAdjAllowdTimeout[%d], GearLvrIndcn2[%d] ,drvrSeatBtnPsd[%d]",
                    SIGNAL.getVehModMngtGlbSafe1CarModSts1(),
                    SIGNAL.getVehModMngtGlbSafe1UsgModSts(), SIGNAL.getcarconfig472(),
                    SIGNAL.getcarconfig1173(), drvrSeatExtAdjAllowd, drvrSeatExtAdjAllowdTimeout,
                    gearLvrIndcn, static_cast<int32_t>(drvrSeatBtnPsd));
                if (gearLvrIndcn != sdb::GearLvrIndcn2::ParkIndcn) {
                    drvrSeatExtAdjAllowd = sdb::Boolean::FALSE;
                } else if (drvrSeatExtAdjAllowdTimeout == sdb::Timeout::Timeout) {
                    if (SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModActv,
                                         sdb::UsgModSts1::UsgModDrvg)) {
                        drvrSeatExtAdjAllowd = sdb::Boolean::FALSE;
                    } else {
                        drvrSeatExtAdjAllowd = m_LastDrvrSeatExtAdjAllowdMove_SeatExt;
                    }
                }
                m_LastDrvrSeatExtAdjAllowdMove_SeatExt = drvrSeatExtAdjAllowd;
                if (SIGNAL.carConfigIs(SignalRX::carconfig472,
                                       sdb::CarConfig472::_02,
                                       sdb::CarConfig472::_03) &&
                    SIGNAL.carConfigIs(SignalRX::carconfig1173,
                                       sdb::CarConfig1173::_02)) {
                    if (SIGNAL.carModeIs(sdb::CarModSts1::CarModCrash,
                                         sdb::CarModSts1::CarModDyno,
                                         sdb::CarModSts1::CarModNorm) &&
                        SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModInActv,
                                         sdb::UsgModSts1::UsgModCnvinc,
                                         sdb::UsgModSts1::UsgModActv,
                                         sdb::UsgModSts1::UsgModDrvg) &&
                        drvrSeatExtAdjAllowd == sdb::Boolean::TRUE &&
                        drvrSeatBtnPsd == sdb::Boolean::FALSE) {
                        VHALOG.d("SEAT_FORE_AFT_MOVE drvr Active");
                        return PropertyStatus::Active;
                    } else {
                        VHALOG.d("SEAT_FORE_AFT_MOVE drvr NotActive");
                        return PropertyStatus::NotActive;
                    }
                } else {
                    VHALOG.d("SEAT_FORE_AFT_MOVE drvr NotAvailable");
                    return PropertyStatus::NotAvailable;
                }
            },
            SignalRX::carconfig1173,
            SignalRX::carconfig472,
            SignalRX::VehModMngtGlbSafe1UsgModSts,
            SignalRX::VehModMngtGlbSafe1CarModSts1,
            SignalRX::DrvrSeatExtAdjAllowd,
            SignalRX::DrvrSeatExtAdjAllowdTimeout,
            SignalRX::GearLvrIndcn,
            SignalRX::DrvrSeatBtnPsd)
        .withValueBySignals(
            []([[maybe_unused]] const SeatLengthMode& last) {
                auto sldSts = SIGNAL.getDrvrSeatSwtStsDrvrSeatSwtSldSts();
                auto sldPerc = static_cast<int32_t>(SIGNAL.getDrvrSeatPosPercSeatPosSldPerc());
                bool qfIsReaday = SIGNAL.getDrvrSeatPosPercSeatPosSldQF() == sdb::Qf1::DataCalcdWithDevDefd;
                auto drvrSeatBtnPsd = SIGNAL.getDrvrSeatBtnPsd();
                VHALOG.d("SEAT_FORE_AFT_MOVE  drvr last:%d, sldSts:%d sldPerc:%d drvrSeatBtnPsd:%d", toInt(last),
                         static_cast<int32_t>(sldSts), sldPerc, static_cast<int32_t>(drvrSeatBtnPsd));

                if (drvrSeatBtnPsd == sdb::Boolean::TRUE ||                                 // 硬按键按下时需要按idle处理
                    (qfIsReaday && (sldPerc == 100 && sldSts == sdb::SwtHozlSts1::Fwd)) ||  // 无法再向前
                    (qfIsReaday && (sldPerc == 0 && sldSts == sdb::SwtHozlSts1::Backw))) {  // 无法再往后
                    VHALOG.d("SEAT_FORE_AFT_MOVE drvr trigger to idle");
                    SeatAdjustmentChangeVFCMove_IdleToOther(SignalTX::SeatLenAdjmtRowFirstDrvr,
                                                            static_cast<int32_t>(sdb::SwtHozlSts1::Idle));

                    SIGNAL.setSeatLenAdjmtRowFirstDrvr(sdb::SwtHozlSts1::Idle);
                    return SeatLengthMode::SEAT_LENGTH_OFF;
                }
                return mappingValue(sldSts, SeatLengthMode::SEAT_LENGTH_OFF);
            },
            SignalRX::DrvrSeatPosPercSeatPosSldPerc,
            SignalRX::DrvrSeatPosPercSeatPosSldQF,
            SignalRX::DrvrSeatSwtStsDrvrSeatSwtSldSts,
            SignalRX::DrvrSeatBtnPsd)
        .onSetProperty([](const SeatLengthMode& value) {
            if (value != SeatLengthMode::SEAT_LENGTH_FORWARD &&
                value != SeatLengthMode::SEAT_LENGTH_BACKWARD &&
                value != SeatLengthMode::SEAT_LENGTH_OFF) {
                VHALOG.e("SEAT_FORE_AFT_MOVE drvr: param invalid");
                return;
            }
            bool qfIsReaday = SIGNAL.getDrvrSeatPosPercSeatPosSldQF() == sdb::Qf1::DataCalcdWithDevDefd;
            auto sldPerc = static_cast<int32_t>(SIGNAL.getDrvrSeatPosPercSeatPosSldPerc());
            if (qfIsReaday && sldPerc == 100 && value == SeatLengthMode::SEAT_LENGTH_FORWARD) {
                VHALOG.e("SEAT_FORE_AFT_MOVE drvr: the percent is 100 , can not forward");
                SIGNAL.setSeatLenAdjmtRowFirstDrvr(sdb::SwtHozlSts1::Idle);
                return;
            } else if (qfIsReaday && sldPerc == 0 && value == SeatLengthMode::SEAT_LENGTH_BACKWARD) {
                VHALOG.e("SEAT_FORE_AFT_MOVE drvr: the percent is 0 , can not backward");
                SIGNAL.setSeatLenAdjmtRowFirstDrvr(sdb::SwtHozlSts1::Idle);
                return;
            }
            VHALOG.d("SEAT_FORE_AFT_MOVE drvr: setValue[%d]", value);

            sdb::SwtHozlSts1 TempSeatLenAdjmtRowFirstDrvr = mappingValue(value, sdb::SwtHozlSts1::Idle);
            SeatAdjustmentChangeVFCMove_IdleToOther(SignalTX::SeatLenAdjmtRowFirstDrvr, static_cast<int32_t>(TempSeatLenAdjmtRowFirstDrvr));
            SIGNAL.setSeatLenAdjmtRowFirstDrvr(TempSeatLenAdjmtRowFirstDrvr);
        })
        .area(VehicleAreaSeat::ROW_1_RIGHT)
        .initValue([]() { return SeatLengthMode::SEAT_LENGTH_OFF; })
        .withStatusBySignals(
            []([[maybe_unused]] const PropertyStatus& last) {
                auto passSeatBtnPsd = SIGNAL.getPassSeatBtnPsd();
                VHALOG.d(
                    "SEAT_FORE_AFT_MOVE pass carmod[%d], "
                    "usgmod[%d], cc472[%d], cc1174[%d] passSeatBtnPsd[%d]",
                    SIGNAL.getVehModMngtGlbSafe1CarModSts1(),
                    SIGNAL.getVehModMngtGlbSafe1UsgModSts(), SIGNAL.getcarconfig472(),
                    SIGNAL.getcarconfig1174(), static_cast<int32_t>(passSeatBtnPsd));

                if (SIGNAL.carConfigIs(SignalRX::carconfig472,
                                       sdb::CarConfig472::_02) &&
                    SIGNAL.carConfigIs(SignalRX::carconfig1174,
                                       sdb::CarConfig1174::_02)) {
                    if (SIGNAL.carModeIs(sdb::CarModSts1::CarModCrash,
                                         sdb::CarModSts1::CarModDyno,
                                         sdb::CarModSts1::CarModNorm) &&
                        SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModInActv,
                                         sdb::UsgModSts1::UsgModCnvinc,
                                         sdb::UsgModSts1::UsgModActv,
                                         sdb::UsgModSts1::UsgModDrvg) &&
                        passSeatBtnPsd == sdb::Boolean::FALSE) {
                        VHALOG.d("SEAT_FORE_AFT_MOVE pass Active");
                        return PropertyStatus::Active;
                    } else {
                        VHALOG.d("SEAT_FORE_AFT_MOVE pass NotActive");
                        return PropertyStatus::NotActive;
                    }
                } else {
                    VHALOG.d("SEAT_FORE_AFT_MOVE pass NotAvailable");
                    return PropertyStatus::NotAvailable;
                }
            },
            SignalRX::carconfig1174,
            SignalRX::carconfig472,
            SignalRX::VehModMngtGlbSafe1UsgModSts,
            SignalRX::VehModMngtGlbSafe1CarModSts1,
            SignalRX::PassSeatBtnPsd)
        .withValueBySignals(
            []([[maybe_unused]] const SeatLengthMode& last) {
                auto sldSts = SIGNAL.getPassSeatSwtSts2PassSeatSwtSldSts();
                auto sldPerc = static_cast<int32_t>(SIGNAL.getPassSeatPosPercSeatPosSldPerc());
                bool qfIsReaday = SIGNAL.getPassSeatPosPercSeatPosSldQF() == sdb::Qf1::DataCalcdWithDevDefd;
                auto passSeatBtnPsd = SIGNAL.getPassSeatBtnPsd();
                VHALOG.d("SEAT_FORE_AFT_MOVE  pass last:%d, sldSts:%d sldPerc:%d passSeatBtnPsd:%d", toInt(last),
                         static_cast<int32_t>(sldSts), sldPerc, static_cast<int32_t>(passSeatBtnPsd));

                if (passSeatBtnPsd == sdb::Boolean::TRUE ||                                 // 硬按键按下时需要按idle处理
                    (qfIsReaday && (sldPerc == 100 && sldSts == sdb::SwtHozlSts1::Fwd)) ||  // 无法再向前
                    (qfIsReaday && (sldPerc == 0 && sldSts == sdb::SwtHozlSts1::Backw))) {  // 无法再往后
                    VHALOG.d("SEAT_FORE_AFT_MOVE pass trigger to idle");
                    SeatAdjustmentChangeVFCMove_IdleToOther(
                        SignalTX::SeatLenAdjmtRowFirstPass,
                        static_cast<int32_t>(sdb::SwtHozlSts1::Idle));
                    SIGNAL.setSeatLenAdjmtRowFirstPass(sdb::SwtHozlSts1::Idle);
                    return SeatLengthMode::SEAT_LENGTH_OFF;
                }
                return mappingValue(sldSts, SeatLengthMode::SEAT_LENGTH_OFF);
            },
            SignalRX::PassSeatPosPercSeatPosSldPerc,
            SignalRX::PassSeatPosPercSeatPosSldQF,
            SignalRX::PassSeatSwtSts2PassSeatSwtSldSts,
            SignalRX::PassSeatBtnPsd)
        .onSetProperty([](const SeatLengthMode& value) {
            if (value != SeatLengthMode::SEAT_LENGTH_FORWARD &&
                value != SeatLengthMode::SEAT_LENGTH_BACKWARD &&
                value != SeatLengthMode::SEAT_LENGTH_OFF) {
                VHALOG.d("SEAT_FORE_AFT_MOVE pass: param invalid");
                return;
            }

            bool qfIsReaday = SIGNAL.getPassSeatPosPercSeatPosSldQF() == sdb::Qf1::DataCalcdWithDevDefd;
            auto sldPerc = static_cast<int32_t>(SIGNAL.getPassSeatPosPercSeatPosSldPerc());
            if (qfIsReaday && sldPerc == 100 && value == SeatLengthMode::SEAT_LENGTH_FORWARD) {
                VHALOG.e("SEAT_FORE_AFT_MOVE pass: the percent is 100 , can not forward");
                SIGNAL.setSeatLenAdjmtRowFirstPass(sdb::SwtHozlSts1::Idle);
                return;
            } else if (qfIsReaday && sldPerc == 0 && value == SeatLengthMode::SEAT_LENGTH_BACKWARD) {
                VHALOG.e("SEAT_FORE_AFT_MOVE pass: the percent is 0 , can not backward");
                SIGNAL.setSeatLenAdjmtRowFirstPass(sdb::SwtHozlSts1::Idle);
                return;
            }
            VHALOG.d("SEAT_FORE_AFT_MOVE pass: setValue[%d]", value);

            sdb::SwtHozlSts1 TempSeatLenAdjmtRowFirstPass = mappingValue(value, sdb::SwtHozlSts1::Idle);
            SeatAdjustmentChangeVFCMove_IdleToOther(
                SignalTX::SeatLenAdjmtRowFirstPass,
                static_cast<int32_t>(TempSeatLenAdjmtRowFirstPass));
            SIGNAL.setSeatLenAdjmtRowFirstPass(TempSeatLenAdjmtRowFirstPass);
        }) 
        // HY11 [SW_FC_004_049]第二排座椅滑移-二排左侧座椅滑移
        .area(VehicleAreaSeat::ROW_2_LEFT)
        .initValue([]() { return SeatLengthMode::SEAT_LENGTH_OFF; })
        .withStatusBySignals(
            []([[maybe_unused]] const PropertyStatus& last) {
                auto rowSecLeBtnPsd = SIGNAL.getRowSecLeBtnPsd();
                VHALOG.d(
                    "SEAT_FORE_AFT_MOVE ROW_2_LEFT carmod[%d], "
                    "usgmod[%d], cc472[%d], rowSecLeBtnPsd[%d]",
                    SIGNAL.getVehModMngtGlbSafe1CarModSts1(),
                    SIGNAL.getVehModMngtGlbSafe1UsgModSts(), SIGNAL.getcarconfig472(), 
                    static_cast<int32_t>(rowSecLeBtnPsd));

                if (SIGNAL.carConfigIs(SignalRX::carconfig474,
                                       sdb::CarConfig474::_02,
                                       sdb::CarConfig474::_04,
                                       sdb::CarConfig474::_05,
                                       sdb::CarConfig474::_81)) {
                    if (SIGNAL.carModeIs(sdb::CarModSts1::CarModCrash,
                                         sdb::CarModSts1::CarModDyno,
                                         sdb::CarModSts1::CarModNorm) &&
                       !SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModAbdnd)  &&
                        rowSecLeBtnPsd == sdb::Boolean::FALSE) {
                        VHALOG.d("SEAT_FORE_AFT_MOVE ROW_2_LEFT Active");
                        return PropertyStatus::Active;
                    } else {
                        VHALOG.d("SEAT_FORE_AFT_MOVE ROW_2_LEFT NotActive");
                        return PropertyStatus::NotActive;
                    }
                } else {
                    VHALOG.d("SEAT_FORE_AFT_MOVE ROW_2_LEFT NotAvailable");
                    return PropertyStatus::NotAvailable;
                }
            },
            SignalRX::carconfig474,
            SignalRX::VehModMngtGlbSafe1UsgModSts,
            SignalRX::VehModMngtGlbSafe1CarModSts1,
            SignalRX::RowSecLeBtnPsd)
        .withValueBySignals(
            []([[maybe_unused]] const SeatLengthMode& last) {
                //动画提示
                auto sldSts = SIGNAL.getSeatRowSecLeSwtStsPassSeatSwtSldSts();
                //实时位置信息
                auto sldPerc = static_cast<int32_t>(SIGNAL.getRowSecLeSldPosPercSeatPosPerc());
                //信号质量
                bool qfIsReaday = SIGNAL.getRowSecLeSldPosPercSeatPosQf() == sdb::Qf1::DataCalcdWithDevDefd;
                //物理按键是否触发
                auto rowSecLeBtnPsd = SIGNAL.getRowSecLeBtnPsd();
                VHALOG.d("SEAT_FORE_AFT_MOVE  ROW_2_LEFT last:%d, sldSts:%d sldPerc:%d rowSecLeBtnPsd:%d", toInt(last),
                         static_cast<int32_t>(sldSts), sldPerc, static_cast<int32_t>(rowSecLeBtnPsd));

                if (rowSecLeBtnPsd == sdb::Boolean::TRUE ||                                 // 硬按键按下时需要按idle处理
                    (qfIsReaday && (sldPerc == 100 && sldSts == sdb::SwtHozlSts1::Fwd)) ||  // 无法再向前
                    (qfIsReaday && (sldPerc == 0 && sldSts == sdb::SwtHozlSts1::Backw))) {  // 无法再往后
                    VHALOG.d("SEAT_FORE_AFT_MOVE ROW_2_LEFT trigger to idle");
                    SeatAdjustmentChangeVFCMove_IdleToOther(
                        SignalTX::LenAdjmtRowSecLe,
                        static_cast<int32_t>(sdb::SwtHozlSts1::Idle));
                    SIGNAL.setLenAdjmtRowSecLe(sdb::SwtHozlSts1::Idle);
                    return SeatLengthMode::SEAT_LENGTH_OFF;
                }
                return mappingValue(sldSts, SeatLengthMode::SEAT_LENGTH_OFF);
            },
            SignalRX::RowSecLeSldPosPercSeatPosPerc,
            SignalRX::RowSecLeSldPosPercSeatPosQf,
            SignalRX::SeatRowSecLeSwtStsPassSeatSwtSldSts,
            SignalRX::RowSecLeBtnPsd)
        .onSetProperty([](const SeatLengthMode& value) {
            if (value != SeatLengthMode::SEAT_LENGTH_FORWARD &&
                value != SeatLengthMode::SEAT_LENGTH_BACKWARD &&
                value != SeatLengthMode::SEAT_LENGTH_OFF) {
                VHALOG.d("SEAT_FORE_AFT_MOVE ROW_2_LEFT: param invalid");
                return;
            }

            bool qfIsReaday = SIGNAL.getRowSecLeSldPosPercSeatPosQf() == sdb::Qf1::DataCalcdWithDevDefd;
            auto sldPerc = static_cast<int32_t>(SIGNAL.getRowSecLeSldPosPercSeatPosPerc());
            if (qfIsReaday && sldPerc == 100 && value == SeatLengthMode::SEAT_LENGTH_FORWARD) {
                VHALOG.e("SEAT_FORE_AFT_MOVE ROW_2_LEFT: the percent is 100 , can not forward");
                SIGNAL.setLenAdjmtRowSecLe(sdb::SwtHozlSts1::Idle);
                return;
            } else if (qfIsReaday && sldPerc == 0 && value == SeatLengthMode::SEAT_LENGTH_BACKWARD) {
                VHALOG.e("SEAT_FORE_AFT_MOVE ROW_2_LEFT: the percent is 0 , can not backward");
                SIGNAL.setLenAdjmtRowSecLe(sdb::SwtHozlSts1::Idle);
                return;
            }
            VHALOG.d("SEAT_FORE_AFT_MOVE ROW_2_LEFT: setValue[%d]", value);

            sdb::SwtHozlSts1 tempLenAdjmtRowSecLe = mappingValue(value, sdb::SwtHozlSts1::Idle);
            SeatAdjustmentChangeVFCMove_IdleToOther(
                SignalTX::LenAdjmtRowSecLe,
                static_cast<int32_t>(tempLenAdjmtRowSecLe));
            SIGNAL.setLenAdjmtRowSecLe(tempLenAdjmtRowSecLe);
        })
        //二排右侧座椅滑移
         .area(VehicleAreaSeat::ROW_2_RIGHT)
        .initValue([]() { return SeatLengthMode::SEAT_LENGTH_OFF; })
        .withStatusBySignals(
            []([[maybe_unused]] const PropertyStatus& last) {
                auto rowSecRiBtnPsd = SIGNAL.getRowSecRiBtnPsd();
                VHALOG.d(
                    "SEAT_FORE_AFT_MOVE ROW_2_RIGHT carmod[%d], "
                    "usgmod[%d], cc472[%d], rowSecRiBtnPsd[%d]",
                    SIGNAL.getVehModMngtGlbSafe1CarModSts1(),
                    SIGNAL.getVehModMngtGlbSafe1UsgModSts(), SIGNAL.getcarconfig472(), 
                    static_cast<int32_t>(rowSecRiBtnPsd));

                if (SIGNAL.carConfigIs(SignalRX::carconfig474,
                                       sdb::CarConfig474::_02,
                                       sdb::CarConfig474::_04,
                                       sdb::CarConfig474::_05,
                                       sdb::CarConfig474::_81)) {
                    if (SIGNAL.carModeIs(sdb::CarModSts1::CarModCrash,
                                         sdb::CarModSts1::CarModDyno,
                                         sdb::CarModSts1::CarModNorm) &&
                       !SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModAbdnd)  &&
                        rowSecRiBtnPsd == sdb::Boolean::FALSE) {
                        VHALOG.d("SEAT_FORE_AFT_MOVE ROW_2_RIGHT Active");
                        return PropertyStatus::Active;
                    } else {
                        VHALOG.d("SEAT_FORE_AFT_MOVE ROW_2_RIGHT NotActive");
                        return PropertyStatus::NotActive;
                    }
                } else {
                    VHALOG.d("SEAT_FORE_AFT_MOVE ROW_2_RIGHT NotAvailable");
                    return PropertyStatus::NotAvailable;
                }
            },
            SignalRX::carconfig474,
            SignalRX::VehModMngtGlbSafe1UsgModSts,
            SignalRX::VehModMngtGlbSafe1CarModSts1,
            SignalRX::RowSecRiBtnPsd)
        .withValueBySignals(
            []([[maybe_unused]] const SeatLengthMode& last) {
                //动画提示
                auto sldSts = SIGNAL.getSeatRowSecRiSwtStsPassSeatSwtSldSts();
                //实时位置信息
                auto sldPerc = static_cast<int32_t>(SIGNAL.getRowSecRiSldPosPercSeatPosPerc());
                //信号质量
                bool qfIsReaday = SIGNAL.getRowSecRiSldPosPercSeatPosQf() == sdb::Qf1::DataCalcdWithDevDefd;
                //物理按键是否触发
                auto rowSecRiBtnPsd = SIGNAL.getRowSecRiBtnPsd();
                VHALOG.d("SEAT_FORE_AFT_MOVE  ROW_2_RIGHT last:%d, sldSts:%d sldPerc:%d rowSecRiBtnPsd:%d", toInt(last),
                         static_cast<int32_t>(sldSts), sldPerc, static_cast<int32_t>(rowSecRiBtnPsd));

                if (rowSecRiBtnPsd == sdb::Boolean::TRUE ||                                 // 硬按键按下时需要按idle处理
                    (qfIsReaday && (sldPerc == 100 && sldSts == sdb::SwtHozlSts1::Fwd)) ||  // 无法再向前
                    (qfIsReaday && (sldPerc == 0 && sldSts == sdb::SwtHozlSts1::Backw))) {  // 无法再往后
                    VHALOG.d("SEAT_FORE_AFT_MOVE ROW_2_RIGHT trigger to idle");
                    SeatAdjustmentChangeVFCMove_IdleToOther(
                        SignalTX::LenAdjmtRowSecRi,
                        static_cast<int32_t>(sdb::SwtHozlSts1::Idle));
                    SIGNAL.setLenAdjmtRowSecRi(sdb::SwtHozlSts1::Idle);
                    return SeatLengthMode::SEAT_LENGTH_OFF;
                }
                return mappingValue(sldSts, SeatLengthMode::SEAT_LENGTH_OFF);
            },
            SignalRX::RowSecRiSldPosPercSeatPosPerc,
            SignalRX::RowSecRiSldPosPercSeatPosQf,
            SignalRX::SeatRowSecRiSwtStsPassSeatSwtSldSts,
            SignalRX::RowSecRiBtnPsd)
        .onSetProperty([](const SeatLengthMode& value) {
            if (value != SeatLengthMode::SEAT_LENGTH_FORWARD &&
                value != SeatLengthMode::SEAT_LENGTH_BACKWARD &&
                value != SeatLengthMode::SEAT_LENGTH_OFF) {
                VHALOG.d("SEAT_FORE_AFT_MOVE ROW_2_RIGHT: param invalid");
                return;
            }

            bool qfIsReaday = SIGNAL.getRowSecRiSldPosPercSeatPosQf() == sdb::Qf1::DataCalcdWithDevDefd;
            auto sldPerc = static_cast<int32_t>(SIGNAL.getRowSecRiSldPosPercSeatPosPerc());
            if (qfIsReaday && sldPerc == 100 && value == SeatLengthMode::SEAT_LENGTH_FORWARD) {
                VHALOG.e("SEAT_FORE_AFT_MOVE ROW_2_RIGHT: the percent is 100 , can not forward");
                SIGNAL.setLenAdjmtRowSecRi(sdb::SwtHozlSts1::Idle);
                return;
            } else if (qfIsReaday && sldPerc == 0 && value == SeatLengthMode::SEAT_LENGTH_BACKWARD) {
                VHALOG.e("SEAT_FORE_AFT_MOVE ROW_2_RIGHT: the percent is 0 , can not backward");
                SIGNAL.setLenAdjmtRowSecRi(sdb::SwtHozlSts1::Idle);
                return;
            }
            VHALOG.d("SEAT_FORE_AFT_MOVE ROW_2_RIGHT: setValue[%d]", value);

            sdb::SwtHozlSts1 tempLenAdjmtRowSecRi = mappingValue(value, sdb::SwtHozlSts1::Idle);
            SeatAdjustmentChangeVFCMove_IdleToOther(
                SignalTX::LenAdjmtRowSecRi,
                static_cast<int32_t>(tempLenAdjmtRowSecRi));
            SIGNAL.setLenAdjmtRowSecRi(tempLenAdjmtRowSecRi);
        });
}